namespace MicroCloud.CodeGeneration.Entities
{
    /// <summary>
    /// 实体类：代码项目信息
    /// </summary>
    [Description("代码项目信息")]
    [Table(nameof(CodeProject), Schema = Constants.Schema)]
    public class CodeProject : EntityBase<Guid>, ICreatedTime
    {
        [DisplayName("项目描述"), Required, StringLength(200)]
        public string Name { get; set; }

        [DisplayName("项目命名空间前缀，通常形如“公司.项目”"), Required, StringLength(200)]
        public string NamespacePrefix { get; set; }

        [DisplayName("公司"), StringLength(200)]
        public string Company { get; set; }

        [DisplayName("创建者"), StringLength(200)]
        public string Creator { get; set; }

        [DisplayName("版权信息"), StringLength(500)]
        public string Copyright { get; set; }

        [DisplayName("根目录"), StringLength(200)]
        public string RootPath { get; set; }

        [DisplayName("创建日期")]
        public DateTime CreatedTime { get; set; }

        /// <summary>
        /// 获取或设置 模块信息集合
        /// </summary>
        public virtual ICollection<CodeModule> Modules { get; set; } = new List<CodeModule>();

        /// <summary>
        /// 获取或设置 项目模板集合
        /// </summary>
        [JsonIgnore]
        public virtual ICollection<CodeProjectTemplate> ProjectTemplates { get; set; } = new List<CodeProjectTemplate>();

        /// <summary>
        /// 获取项目名称
        /// </summary>
        //public string GetName()
        //{
        //    return $"{Name}[{NamespacePrefix}]";
        //}

        /// <summary>
        /// 从项目命名空间前缀,获取项目代码名称
        /// </summary>
        public string GetCode()
        {
            var arr = NamespacePrefix.Split('.');
            if (arr.Length == 2) return arr[1];
            else return NamespacePrefix.Replace(".", string.Empty);
        }
    }
}